import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {h} from 'vue';

export const columns: BasicColumn[] = [
  {
    title: '学号',
    align:"center",
    dataIndex: 'code',
    fixed:'left'
  },
  {
    title: '姓名',
    align:"center",
    dataIndex: 'name',
    fixed:'left'
  },
  {
    title: '部门',
    align:"center",
    dataIndex: 'departmentId_dictText',
    fixed:'left'
  },
  {
    title: '最终结果',
    align:"center",
    dataIndex: 'statusSlot',
    slots: { customRender: 'statusSlot' }
  },
  {
    title: '请假事由',
    align:"center",
    dataIndex: 'content'
  },
  {
    title: '类型',
    align:"center",
    dataIndex: 'afltype',
    customRender:({text}) => {
      return  render.renderDict(text, 'afl_type');
    },
  },
  {
    title: '天数',
    align:"center",
    dataIndex: 'numofdate'
  },
  {
    title: '开始时间',
    align:"center",
    dataIndex: 'sdate'
  },
  {
    title: '结束时间',
    align:"center",
    dataIndex: 'edate'
  },

  {
    title: '是否出校',
    align:"center",
    dataIndex: 'outschool',
    customRender:({text}) =>{
      return !text?"":(text==0?"否":"是")
    },
  },
  /* {
    title: '班主任老师',
    align:"center",
    dataIndex: 'ateacherName'
   }, */
  {
    title: '是否销假',
    align:"center",
    dataIndex: 'isResumption',
    customRender:({text}) =>{
      return !text?"":(text==0?"否":"是")
    },
  },
  {
    title: '销假时间',
    align:"center",
    dataIndex: 'resumptionDate',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
  },
  {
    title: '是否撤销',
    align:"center",
    dataIndex: 'isCancel',
    customRender:({text}) =>{
      return text=="0"?"否":"是"
    },
  },
  {
    title: '离校方式',
    align:"center",
    dataIndex: 'leaveMode',
    customRender:({text}) =>{
      return text=='1'?"家长接送":"自行回家"
    },
  },
  {
    title: '是否放行',
    align:"center",
    dataIndex: 'isPass',
    customRender:({text}) =>{
      return text==0?"否":"是"
    },
  },
  {
    title: '创建时间',
    align:"center",
    dataIndex: 'createdate'
  },
  {
    title: '更新时间',
    align:"center",
    dataIndex: 'updatedate'
  },
];
//列表数据
export const columnsAudit: BasicColumn[] = [
   {
    title: '学号',
    align:"center",
    dataIndex: 'code',
    fixed:'left'
   },
   {
    title: '姓名',
    align:"center",
    dataIndex: 'name',
    fixed:'left'
   },
   {
    title: '部门',
    align:"center",
    dataIndex: 'departmentId_dictText',
    fixed:'left'
   },
  {
    title: '最终结果',
    align:"center",
    dataIndex: 'statusSlot',
    slots: { customRender: 'statusSlot' }
  },
  {
    title: '我的审批',
    align:"center",
    dataIndex: 'applyResultResult',
    customRender:({text}) => {
      return  render.renderDict(text,'att_event_reg_status')
    },
  },
   {
    title: '请假事由',
    align:"center",
    dataIndex: 'content'
   },
   {
    title: '类型',
    align:"center",
    dataIndex: 'afltype',
    customRender:({text}) => {
        return  render.renderDict(text, 'afl_type');
    },
   },
   {
    title: '天数',
    align:"center",
    dataIndex: 'numofdate'
   },
   {
    title: '开始时间',
    align:"center",
    dataIndex: 'sdate'
   },
   {
    title: '结束时间',
    align:"center",
    dataIndex: 'edate'
   },

   {
    title: '是否出校',
    align:"center",
    dataIndex: 'outschool',
    customRender:({text}) =>{
      return !text?"":(text==0?"否":"是")
    },
   },
  /* {
    title: '班主任老师',
    align:"center",
    dataIndex: 'ateacherName'
   }, */
   {
    title: '是否销假',
    align:"center",
    dataIndex: 'isResumption',
    customRender:({text}) =>{
      return !text?"":(text==0?"否":"是")
    },
   },
   {
    title: '销假时间',
    align:"center",
    dataIndex: 'resumptionDate',
    customRender:({text}) =>{
      return !text?"":(text.length>10?text.substr(0,10):text)
    },
   },
   {
    title: '是否撤销',
    align:"center",
    dataIndex: 'isCancel',
    customRender:({text}) =>{
      return text=="0"?"否":"是"
    },
   },
   {
    title: '离校方式',
    align:"center",
    dataIndex: 'leaveMode',
    customRender:({text}) =>{
      return text=='1'?"家长接送":"自行回家"
    },
   },
   {
    title: '是否放行',
    align:"center",
    dataIndex: 'isPass',
    customRender:({text}) =>{
      return text==0?"否":"是"
    },
   },
   {
    title: '创建时间',
    align:"center",
    dataIndex: 'createdate'
   },
   {
    title: '更新时间',
    align:"center",
    dataIndex: 'updatedate'
   },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
	{
      label: "类型",
      field: 'afltype',
      component: 'JDictSelectTag',
      componentProps:{
           dictCode:"afl_type",
           stringToNumber: true
       }
      
      //colProps: {span: 6},
 	},
  {
   label: '学号',
   field: 'code',
   component: 'Input'
  },
  {
   label: '姓名',
   field: 'name',
   component: 'Input'
  },
  {
      label: "部门",
      field: 'departmentId',
      component: 'JSelectDept',
    componentProps:{
      checkStrictly:false,
      multiple:false
    },

      
      //colProps: {span: 6},
  },
  {  //勿删
      label: "审核状态",
      field: 'status',
      component: 'JSelectInput',
      componentProps: {
        options: [
          { label: '待审核', value: '0' },
          { label: '通过', value: '1' },
          { label: '未通过', value: '2' },
        ],
      },
    show:false,
  },
/*	{
      label: "审批人",
      field: 'reviewName',
      component: 'Input'
      //colProps: {span: 6},
 	},*/
     {
      label: "创建时间",
      field: "createdate",
      component: 'RangePicker',
      componentProps: {
          valueType: 'Date',
          showTime:true
      },
      //colProps: {span: 6},
	},
];
//表单数据
export const formSchemaAudit: FormSchema[] = [
  {
    label: '人员',
    field: 'personid',
    component: 'JSelectPerson',
    componentProps: {
      labelKey: 'name',
      isRadioSelection: true
    },
    dynamicDisabled: ({values}) => {
      return values.id;
    },
  },

  {
    label: '类型',
    field: 'afltype',
    component: 'JDictSelectTag',
    componentProps: ({ formModel }) => {
      return {
        dictCode:"afl_type",
        stringToNumber:true,
        onChange: (e) => {
        },
      };
    },
  },

  {
    label: '开始时间',
    field: 'sdate',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入开始时间!'},
      ];
    },
  },
  {
    label: '结束时间',
    field: 'edate',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入结束时间!'},
      ];
    },
  },
  {
    label: '天数',
    field: 'numofdate',
    component: 'InputNumber',
  },
  {
    label: '离校方式',
    field: 'leaveMode',
    component: 'Select',
    defaultValue:"1",
    componentProps:{
      options:[{label:"家长接送",value:"1"},{label:"自行回家",value:"2"}]
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入离校方式'},
      ];
    },
  },
  {
    label: '请假事由',
    field: 'content',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入请假事由!'},
      ];
    },
  },


  {
    label: '状态',
    field: 'status',
    component: 'RadioGroup',
    componentProps:{
      options:[
        {
          label:'通过',
          value:'1'
        },
        {
          label:'不通过',
          value:'2'
        }
      ]
    },
    // defaultValue: '1',
    show: ({values})=>{
      return values.applyResultId
    },
  },
  {
    label: '意见',
    field: 'resultRemark',
    component: 'InputTextArea',
    show: ({values})=>{
      return values.applyResultId
    },
  },
  {
    label: '',
    field: 'applyResultId',
    component: 'Input',
    show:false,
  },



  // {
  //   label: '删除标识',
  //   field: 'delFlag',
  //   component: 'Input',
  // },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'isAudit',
    defaultValue: 2,
    component: 'Input',
    show: false
  },

  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];
export const formSchema: FormSchema[] = [


  {
    label: '类型',
    field: 'afltype',
    component: 'JDictSelectTag',
    componentProps: ({ formModel }) => {
      return {
        dictCode:"afl_type",
        stringToNumber:true,
        onChange: (e) => {
        },
      };
    },
  },

  {
    label: '开始时间',
    field: 'sdate',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入开始时间!'},
      ];
    },
  },
  {
    label: '结束时间',
    field: 'edate',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入结束时间!'},
      ];
    },
  },
  {
    label: '天数',
    field: 'numofdate',
    component: 'InputNumber',
  },
  {
    label: '离校方式',
    field: 'leaveMode',
    component: 'Select',
    defaultValue:1,
    componentProps:{
      options:[{label:"家长接送",value:1},{label:"自行回家",value:2}]
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入离校方式'},
      ];
    },
  },
  {
    label: '请假事由',
    field: 'content',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入请假事由!'},
      ];
    },
  },


  {
    label: '状态',
    field: 'status',
    component: 'RadioGroup',
    componentProps:{
      options:[
        {
          label:'通过',
          value:'1'
        },
        {
          label:'不通过',
          value:'2'
        }
      ]
    },
    // defaultValue: '1',
    show: ({values})=>{
      return values.applyResultId
    },
  },
  {
    label: '意见',
    field: 'resultRemark',
    component: 'InputTextArea',
    show: ({values})=>{
      return values.applyResultId
    },
  },
  {
    label: '',
    field: 'applyResultId',
    component: 'Input',
    show:false,
  },



  // {
  //   label: '删除标识',
  //   field: 'delFlag',
  //   component: 'Input',
  // },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'isAudit',
    defaultValue: 2,
    component: 'Input',
    show: false
  },

  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];

export const formSchemaForGuard: FormSchema[] = [
  {
    label: '姓名',
    field: 'name',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入用户ID，请假人!'},
      ];
    },
  },

  {
    label: '请假事由',
    field: 'content',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入请假事由!'},
      ];
    },
  },
  {
    label: '类型',
    field: 'afltype',
    component: 'JDictSelectTag',
    componentProps:{
      dictCode:"afl_type",
      stringToNumber:true,
    }

  },
  {
    label: '天数',
    field: 'numofdate',
    component: 'InputNumber',
  },
  {
    label: '开始时间',
    field: 'sdate',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入开始时间!'},
      ];
    },
  },
  {
    label: '结束时间',
    field: 'edate',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入结束时间!'},
      ];
    },
  },
  {
    label: '审批人',
    field: 'reviewid',
    component: 'JSearchSelect',
    componentProps:{
      dict:"ss_person where status!=0,name,id"
    }
  },

  {
    label: '审核意见',
    field: 'reviewcontent',
    component: 'Input',
  },

  {
    label: '审批状态',
    field: 'status',
    component: 'InputNumber',
    render: ({model,field}) => {
      let str = "";
      if(model[field]==0)
         str = "未审";
      if(model[field]==1)
        str = "通过";
      if(model[field]==2)
        str = "未通过";

      return h("Input",{
         value:str,
        disabled:true,
      })
    },
  },

  ];

// 高级查询数据
export const superQuerySchema = {
  personid: {title: '用户ID，请假人',order: 0,view: 'text', type: 'string'},
  openid: {title: '微信OPENID(留言人)',order: 1,view: 'text', type: 'string'},
  content: {title: '请假事由',order: 2,view: 'text', type: 'string'},
  afltype: {title: '类型 0：事假  1：病假  2：其它',order: 3,view: 'number', type: 'number'},
  numofdate: {title: '天数',order: 4,view: 'number', type: 'number'},
  sdate: {title: '开始时间',order: 5,view: 'datetime', type: 'string'},
  edate: {title: '结束时间',order: 6,view: 'datetime', type: 'string'},
  reviewid: {title: '审批人',order: 7,view: 'text', type: 'string'},
  delflag: {title: '删除标记 1:删除(default 0)',order: 8,view: 'number', type: 'number'},
  reviewcontent: {title: '审核意见',order: 9,view: 'text', type: 'string'},
  createdate: {title: '创建时间',order: 10,view: 'datetime', type: 'string'},
  updatedate: {title: '更新时间',order: 11,view: 'datetime', type: 'string'},
  status: {title: '审批状态 0:未审 1 通过 2 未通过(default 0)',order: 12,view: 'number', type: 'number'},
  outschool: {title: '是否出校 0:否 1是(default 0)',order: 13,view: 'number', type: 'number'},
  ateacherid: {title: '批假老师ID(',order: 14,view: 'text', type: 'string'},
  isResumption: {title: '是否销假 0否 1 是',order: 15,view: 'text', type: 'string'},
  resumptionDate: {title: '销假时间',order: 16,view: 'date', type: 'string'},
  isCancel: {title: '是否取消請假單0否1是',order: 17,view: 'text', type: 'string'},
  leaveMode: {title: '离校方式：1家长接送 2自行回家，默认为家长接送',order: 18,view: 'text', type: 'string'},
  isPass: {title: '是否放行',order: 19,view: 'number', type: 'number'}
};

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
